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

📄 calc.at

📁 bison 2.0 主要可以用来做语法分析用的
💻 AT
📖 第 1 页 / 共 2 页
字号:
]AT_LALR1_CC_IF([], [m4_bmatch([$4], [%debug],[  yydebug = 1;])])[  status = yyparse (]AT_PARAM_IF([&result, &count])[);  if (global_result != result)    abort ();  if (global_count != count)    abort ();  return status;}]])])# _AT_DATA_CALC_Y# AT_DATA_CALC_Y([BISON-OPTIONS])# -------------------------------# Produce `calc.y'.m4_define([AT_DATA_CALC_Y],[_AT_DATA_CALC_Y($[1], $[2], $[3], [$1])])# _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES = 0])# ------------------------------------------------------------# Run `calc' on INPUT and expect no STDOUT nor STDERR.## If BISON-OPTIONS contains `%debug' but not `%glr-parser', then# NUM-STDERR-LINES is the number of expected lines on stderr.## We don't count GLR's traces yet, since its traces are somewhat# different from LALR's.m4_define([_AT_CHECK_CALC],[AT_DATA([[input]],[[$2]])AT_PARSER_CHECK([./calc input], 0, [], [stderr])m4_bmatch([$1],  [%debug.*%glr\|%glr.*%debug],     [],  [%debug],     [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3])])])# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, EXIT-STATUS, INPUT,#                      [NUM-DEBUG-LINES],#                      [VERBOSE-AND-LOCATED-ERROR-MESSAGE])# ---------------------------------------------------------# Run `calc' on INPUT, and expect a `syntax error' message.## If INPUT starts with a slash, it is used as absolute input file name,# otherwise as contents.## If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION# is correctly output on stderr.## If BISON-OPTIONS contains `%error-verbose', then make sure the# IF-YYERROR-VERBOSE message is properly output after `syntax error, '# on STDERR.## If BISON-OPTIONS contains `%debug' but not `%glr', then NUM-STDERR-LINES# is the number of expected lines on stderr.m4_define([_AT_CHECK_CALC_ERROR],[m4_bmatch([$3], [^/],           [AT_PARSER_CHECK([./calc $3], $2, [], [stderr])],           [AT_DATA([[input]],[[$3]])AT_PARSER_CHECK([./calc input], $2, [], [stderr])])m4_bmatch([$1],  [%debug.*%glr\|%glr.*%debug],     [],  [%debug],     [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$4])])# Normalize the observed and expected error messages, depending upon the# options.# 1. Remove the traces from observed.sed '/^Starting/d/^Entering/d/^Stack/d/^Reading/d/^Reducing/d/^Shifting/d/^state/d/^Error:/d/^Next/d/^Discarding/d/^yydestructor:/d' stderr >at-stderrmv at-stderr stderr# 2. Create the reference error message.AT_DATA([[expout]],[$5])# 3. If locations are not used, remove them.AT_YYERROR_SEES_LOC_IF([],[[sed 's/^[-0-9.]*: //' expout >at-expoutmv at-expout expout]])# 4. If error-verbose is not used, strip the`, unexpected....' part.m4_bmatch([$1], [%error-verbose], [],[[sed 's/syntax error, .*$/syntax error/' expout >at-expoutmv at-expout expout]])# 5. CheckAT_CHECK([cat stderr], 0, [expout])])# AT_CHECK_CALC([BISON-OPTIONS [, EXPECTED-TO-FAIL]])# ------------------------------# Start a testing chunk which compiles `calc' grammar with# BISON-OPTIONS, and performs several tests over the parser.# However, if EXPECTED-TO-FAIL is nonempty, this test is expected to fail.m4_define([AT_CHECK_CALC],[# We use integers to avoid dependencies upon the precision of doubles.AT_SETUP([Calculator $1])m4_ifval([$2], [AT_CHECK([exit 77])])AT_BISON_OPTION_PUSHDEFS([$1])AT_DATA_CALC_Y([$1])AT_LALR1_CC_IF(  [AT_CHECK([bison -o calc.cc calc.y])   AT_COMPILE_CXX([calc])],  [AT_CHECK([bison -o calc.c calc.y])   AT_COMPILE([calc])])# Test the priorities._AT_CHECK_CALC([$1],[1 + 2 * 3 = 71 + 2 * -3 = -5-1^2 = -1(-1)^2 = 1---1 = -11 - 2 - 3 = -41 - (2 - 3) = 22^2^3 = 256(2^2)^3 = 64],               [570])# Some syntax errors._AT_CHECK_CALC_ERROR([$1], [1], [0 0], [13],                     [1.2: syntax error, unexpected "number"])_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [18],                     [1.2: syntax error, unexpected '/', expecting "number" or '-' or '(' or '!'])_AT_CHECK_CALC_ERROR([$1], [1], [error], [5],                     [1.0: syntax error, unexpected $undefined])_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [26],                     [1.6: syntax error, unexpected '='])_AT_CHECK_CALC_ERROR([$1], [1],                     [+1],                     [16],                     [2.0: syntax error, unexpected '+'])# Exercise error messages with EOF: work on an empty file._AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [5],                     [1.0: syntax error, unexpected "end of input"])# Exercise the error token: without it, we die at the first error,# hence be sure to## - have several errors which exercise different shift/discardings#   - (): nothing to pop, nothing to discard#   - (1 + 1 + 1 +): a lot to pop, nothing to discard#   - (* * *): nothing to pop, a lot to discard#   - (1 + 2 * *): some to pop and discard## - test the action associated to `error'## - check the look-ahead that triggers an error is not discarded#   when we enter error recovery.  Below, the look-ahead causing the#   first error is ")", which is needed to recover from the error and#   produce the "0" that triggers the "0 != 1" error.#_AT_CHECK_CALC_ERROR([$1], [0],                     [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],                     [188],[1.1: syntax error, unexpected ')', expecting "number" or '-' or '(' or '!'1.17: syntax error, unexpected ')', expecting "number" or '-' or '(' or '!'1.22: syntax error, unexpected '*', expecting "number" or '-' or '(' or '!'1.40: syntax error, unexpected '*', expecting "number" or '-' or '(' or '!'calc: error: 4444 != 1])# The same, but this time exercising explicitly triggered syntax errors.# POSIX says the look-ahead causing the error should not be discarded._AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [75],[1.9: syntax error, unexpected "number"calc: error: 2222 != 1])_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [85],[1.3: syntax error, unexpected '*', expecting "number" or '-' or '(' or '!'1.11: syntax error, unexpected "number"calc: error: 2222 != 1])AT_BISON_OPTION_POPDEFSAT_CLEANUP])# AT_CHECK_CALC# ------------------------ ## Simple LALR Calculator.  ## ------------------------ #AT_BANNER([[Simple LALR Calculator.]])# AT_CHECK_CALC_LALR([BISON-OPTIONS])# -----------------------------------# Start a testing chunk which compiles `calc' grammar with# BISON-OPTIONS, and performs several tests over the parser.m4_define([AT_CHECK_CALC_LALR],[AT_CHECK_CALC($@)])AT_CHECK_CALC_LALR()AT_CHECK_CALC_LALR([%defines])AT_CHECK_CALC_LALR([%locations])AT_CHECK_CALC_LALR([%name-prefix="calc"])AT_CHECK_CALC_LALR([%verbose])AT_CHECK_CALC_LALR([%yacc])AT_CHECK_CALC_LALR([%error-verbose])AT_CHECK_CALC_LALR([%pure-parser %locations])AT_CHECK_CALC_LALR([%error-verbose %locations])AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc])AT_CHECK_CALC_LALR([%debug])AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])# ----------------------- ## Simple GLR Calculator.  ## ----------------------- #AT_BANNER([[Simple GLR Calculator.]])# AT_CHECK_CALC_GLR([BISON-OPTIONS])# ----------------------------------# Start a testing chunk which compiles `calc' grammar with# BISON-OPTIONS and %glr-parser, and performs several tests over the parser.m4_define([AT_CHECK_CALC_GLR],[AT_CHECK_CALC([%glr-parser] $@)])AT_CHECK_CALC_GLR()AT_CHECK_CALC_GLR([%defines])AT_CHECK_CALC_GLR([%locations])AT_CHECK_CALC_GLR([%name-prefix="calc"])AT_CHECK_CALC_GLR([%verbose])AT_CHECK_CALC_GLR([%yacc])AT_CHECK_CALC_GLR([%error-verbose])AT_CHECK_CALC_GLR([%pure-parser %locations])AT_CHECK_CALC_GLR([%error-verbose %locations])AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc])AT_CHECK_CALC_GLR([%debug])AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])# ----------------------------- ## Simple LALR1 C++ Calculator.  ## ----------------------------- #AT_BANNER([[Simple LALR1 C++ Calculator.]])# AT_CHECK_CALC_LALR1_CC([BISON-OPTIONS])# ---------------------------------------# Start a testing chunk which compiles `calc' grammar with# the C++ skeleton, and performs several tests over the parser.m4_define([AT_CHECK_CALC_LALR1_CC],[AT_CHECK_CALC([%skeleton "lalr1.cc"] $@)])# AT_CHECK_CALC_LALR1_CC()AT_CHECK_CALC_LALR1_CC([%defines %locations])AT_CHECK_CALC_LALR1_CC([%defines])# AT_CHECK_CALC_LALR1_CC([%locations])# AT_CHECK_CALC_LALR1_CC([%name-prefix="calc"])# AT_CHECK_CALC_LALR1_CC([%verbose])# AT_CHECK_CALC_LALR1_CC([%yacc])# AT_CHECK_CALC_LALR1_CC([%error-verbose])# AT_CHECK_CALC_LALR1_CC([%pure-parser %locations])# AT_CHECK_CALC_LALR1_CC([%error-verbose %locations])AT_CHECK_CALC_LALR1_CC([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc])# AT_CHECK_CALC_LALR1_CC([%debug])AT_CHECK_CALC_LALR1_CC([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc])AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])

⌨️ 快捷键说明

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