X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=lexer.h;h=e419794eda9f867e150e9f26064cd3ef849c9ec6;hb=d72cb42b0883b7f382d9bd1240e78cab34ab14ca;hp=2135ec60ee3f53c3c7ec43866f3701d19cf0a946;hpb=0d33939b1be1b273daf462a070ea6be4c99820e4;p=xonotic%2Fgmqcc.git diff --git a/lexer.h b/lexer.h index 2135ec6..e419794 100644 --- a/lexer.h +++ b/lexer.h @@ -1,5 +1,27 @@ -#ifndef GMQCC_LEXER_HDR_ -#define GMQCC_LEXER_HDR_ +/* + * Copyright (C) 2012 + * Wolfgang Bumiller + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef GMQCC_LEXER_HDR +#define GMQCC_LEXER_HDR typedef struct token_s token; @@ -128,7 +150,7 @@ typedef struct { unsigned int operands; unsigned int id; unsigned int assoc; - unsigned int prec; + signed int prec; unsigned int flags; } oper_info; @@ -182,7 +204,6 @@ static const oper_info c_operators[] = { { "||", 2, opid2('|','|'), ASSOC_LEFT, 4, 0 }, { "?", 3, opid2('?',':'), ASSOC_RIGHT, 3, 0 }, - { ":", 3, opid2(':','?'), ASSOC_RIGHT, 3, 0 }, { "=", 2, opid1('='), ASSOC_RIGHT, 2, 0 }, { "+=", 2, opid2('+','='), ASSOC_RIGHT, 2, 0 }, @@ -196,7 +217,9 @@ static const oper_info c_operators[] = { { "^=", 2, opid2('^','='), ASSOC_RIGHT, 2, 0 }, { "|=", 2, opid2('|','='), ASSOC_RIGHT, 2, 0 }, - { ",", 2, opid1(','), ASSOC_LEFT, 1, 0 } + { ":", 0, opid2(':','?'), ASSOC_RIGHT, 1, 0 }, + + { ",", 2, opid1(','), ASSOC_LEFT, 0, 0 } }; static const size_t c_operator_count = (sizeof(c_operators) / sizeof(c_operators[0])); @@ -230,6 +253,8 @@ static const oper_info fte_operators[] = { { "==", 2, opid2('=','='), ASSOC_LEFT, 10, 0 }, { "!=", 2, opid2('!','='), ASSOC_LEFT, 10, 0 }, + { "?", 3, opid2('?',':'), ASSOC_RIGHT, 9, 0 }, + { "=", 2, opid1('='), ASSOC_RIGHT, 8, 0 }, { "+=", 2, opid2('+','='), ASSOC_RIGHT, 8, 0 }, { "-=", 2, opid2('-','='), ASSOC_RIGHT, 8, 0 }, @@ -243,10 +268,9 @@ static const oper_info fte_operators[] = { { "&&", 2, opid2('&','&'), ASSOC_LEFT, 5, 0 }, { "||", 2, opid2('|','|'), ASSOC_LEFT, 5, 0 }, + /* Leave precedence 3 for : with -fcorrect-ternary */ { ",", 2, opid1(','), ASSOC_LEFT, 2, 0 }, - - { "?", 3, opid2('?',':'), ASSOC_RIGHT, 1, 0 }, - { ":", 3, opid2(':','?'), ASSOC_RIGHT, 1, 0 } + { ":", 0, opid2(':','?'), ASSOC_RIGHT, 1, 0 } }; static const size_t fte_operator_count = (sizeof(fte_operators) / sizeof(fte_operators[0])); @@ -289,9 +313,6 @@ static const oper_info qcc_operators[] = { { "||", 2, opid2('|','|'), ASSOC_LEFT, 5, 0 }, { ",", 2, opid1(','), ASSOC_LEFT, 2, 0 }, - - { "?", 3, opid2('?',':'), ASSOC_RIGHT, 1, 0 }, - { ":", 3, opid2(':','?'), ASSOC_RIGHT, 1, 0 } }; static const size_t qcc_operator_count = (sizeof(qcc_operators) / sizeof(qcc_operators[0]));