⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example1.y

📁 学习lemon语法分析的windows程序
💻 Y
字号:
/* Copyright (GPL) 2004 mchirico@users.sourceforge.net or mchirico@comcast.net  Simple lemon parser  example.      $ ./lemon example1.y                            The above statement will create example1.c.  The command below  adds  main and the  necessary "Parse" calls to the  end of this example1.c.    $ cat <<EOF >>example1.c                          int main()                                        {                                                   void* pParser = ParseAlloc (malloc);              Parse (pParser, INTEGER, 1);                      Parse (pParser, PLUS, 0);                         Parse (pParser, INTEGER, 2);                      Parse (pParser, 0, 0);                            ParseFree(pParser, free );                       }                                                EOF                                                            $ g++ -o ex1 example1.c                                           $ ./ex1  See the Makefile, as most all of this is  done automatically.    Downloads:  http://prdownloads.sourceforge.net/souptonuts/lemon_examples.tar.gz?download*/%token_type {int}     %left PLUS MINUS.   %left DIVIDE TIMES.     %include {   #include <iostream>  #include "example1.h"}     %syntax_error {    std::cout << "Syntax error!" << std::endl;  }      program ::= expr(A).   { std::cout << "Result=" << A << std::endl; }     expr(A) ::= expr(B) MINUS  expr(C).   { A = B - C; }  expr(A) ::= expr(B) PLUS  expr(C).   { A = B + C; }  expr(A) ::= expr(B) TIMES  expr(C).   { A = B * C; }  expr(A) ::= expr(B) DIVIDE expr(C).  {          if(C != 0){           A = B / C;          }else{           std::cout << "divide by zero" << std::endl;           }}  /* end of DIVIDE */expr(A) ::= INTEGER(B). { A = B; } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -