• R/O
  • HTTP
  • SSH
  • HTTPS

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

コンパイラ


File Info

Rev. d85114e8e96ca773d54f7651aab9a16005944069
大小 996 字节
时间 2011-06-13 00:09:32
作者 berupon
Log Message

ISO/IEC 9899:TC3 Annex A Language syntax summary に基づいた Lexer 記述。

Content

<?php

// Tokenのリストを生成するプログラム

if ($argc != 3) {
	printf("usage : %s filename prefix\n", $argv[0]);
	exit;
}

$prefix = $argv[2];	// enum prefix
$lines = file($argv[1], FILE_SKIP_EMPTY_LINES);

$category = "";

foreach ($lines as $line) {
	$str = rtrim($line);
	if (strlen($str) == 0) {
		continue;
	}
	
	$sub = false;
	// subtype token
	$codestr = "";
	if ($str[0] == "\t") {
		$sub = true;
		$str = substr($str, 1);
		
		// single letter token
		if (strlen($str) == 1) {
//			continue;
			$codestr = $category . " | " . "'$str'";
		}else {
			// find alternative token name
			$pos = strpos($str, "\t");
			if ($pos) {
				$codestr = substr($str, $pos+1);
				$str = substr($str, 0, $pos);
			}else {
				$codestr = $str;
			}
		}
	}else {
		$codestr = $str;
		$category = $str;
	}
//	printf("%s%s\r\n", $prefix, $codestr);	// enum entry
//	echo $str[1];
	printf("\"%s\"\t{ return %s%s; }\r\n", $str, $prefix, $codestr);
}


?>