aboutsummaryrefslogtreecommitdiff
path: root/cibic.y
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2014-03-23 16:54:19 +0800
committerTeddy <ted.sybil@gmail.com>2014-03-23 16:54:19 +0800
commit97fb20538cdac668dda0a0aa82884505bc0df61a (patch)
tree755ef3900575f19db533963610db72b79680fc03 /cibic.y
parent7670b6968af891d164d6cae0e42fc35415276b65 (diff)
lexical analysis almost done
Diffstat (limited to 'cibic.y')
-rw-r--r--cibic.y43
1 files changed, 43 insertions, 0 deletions
diff --git a/cibic.y b/cibic.y
new file mode 100644
index 0000000..92f0cfe
--- /dev/null
+++ b/cibic.y
@@ -0,0 +1,43 @@
+%{
+#include <stdio.h>
+%}
+%token IDENTIFIER INT_CONST CHAR_CONST STR_CONST
+%token KW_VOID KW_CHAR KW_INT KW_STRUCT KW_UNION KW_IF KW_ELSE KW_WHILE
+%token KW_FOR KW_CONT KW_BREAK KW_RET KW_SIZEOF
+%token OPT_OR OPT_AND OPT_EQ OPT_NE OPT_LE OPT_GE OPT_SHL OPT_SHR OPT_INC OPT_DEC OPT_PTR
+%token ASS_MUL ASS_DIV ASS_MOD ASS_ADD ASS_SUB ASS_SHL ASS_SHR ASS_AND ASS_XOR ASS_OR
+%token UNKNOWN
+%union {
+ int intval;
+ char *strval;
+}
+%%
+program
+ : body {
+ printf("\n")}
+body
+ : IDENTIFIER
+%%
+int yywrap() {
+ return 1;
+}
+
+int yyerror(char *s) {
+}
+
+extern FILE *yyin;
+int main() {
+ int ret;
+ //yyin = fopen("in", "r");
+ while (ret = yylex())
+ {
+ printf("%d\n", ret);
+ if (ret == IDENTIFIER)
+ printf("id: %s\n", yylval.strval);
+ else if (ret == INT_CONST)
+ printf("int: %d\n", yylval.intval);
+ else if (ret == STR_CONST)
+ printf("str: %s\n", yylval.strval);
+ }
+ return 0;
+}